home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / e / AEPD24.lha / EPD24 / Amiga_E-Programme / FVList / FVNodeTest.e < prev    next >
Text File  |  1980-02-01  |  3KB  |  93 lines

  1. /* FVlist: a class for handling linked-list-stuff with that little extra
  2.  
  3. This kind of linked list has a member pointer to the root of the list,
  4. and this root has a pointer to the tail, so that:
  5. -the root can be reached from every node in one single action (speed)
  6. -the tail can be reached from the root, so that adding a node to this
  7. list (which is always handled with it's root-element) is also quite
  8. fast.
  9.  
  10. I hear you saying: 'why no normal double-linked list?', and you're
  11. right, except for speed.
  12. Maybe you don't give a damn, but I think it's rather handy...
  13.  
  14. Oh yes, the Disclaimer:
  15. 'Use it, but don't blame me if it blows up your dog or eats
  16. your socks (no good idea anyway :) or some other thing.'
  17.  
  18. Hope you like it.  If you find any bugs (prey there aren't any),
  19. please let me know immediately.
  20. Also, tell me what you use it for.
  21.  
  22. Frank Verheyen
  23. The RedHaired Barbarian
  24. --- Nudge Nudge. Say no more ---
  25.     (Monty Python)
  26.  
  27. (EMAIL) hi910097@Beta.Ufsia.ac.be
  28.  
  29. Wouter can include this into his next E-release if it's any good.
  30.  
  31. */
  32. /*--------------------------------------------------------------------------*/
  33. /*--------------------------------------------------------------------------*/
  34.  
  35. MODULE 'FVMods/FVList'
  36.  
  37. /*--------------------------------------------------------------------------*/
  38.  
  39. PROC main()
  40.     DEF    root:PTR TO fvlist,
  41.         node:PTR TO fvnode,
  42.         intermediate1:PTR TO fvnode,
  43.         intermediate2:PTR TO fvnode,
  44.         last:PTR TO fvnode
  45.  
  46.     PrintF('\n\nFVList demo coming up, beware\n')
  47.     NEW root.make(NIL)
  48.     intermediate1 := NEW node.make(root)
  49.     NEW node.make(root)
  50.     intermediate2 := NEW node.make(root)
  51.     NEW node.make(root)
  52.     root.show()
  53.     PrintF('giveRoot() of root = \h\n',root.giveRoot())
  54.     PrintF('giveRoot() of node = \h\n',node.giveRoot())
  55.     PrintF('giveTail() of root = \h\n',root.giveTail())
  56.     PrintF('giveTail() of node = \h\n',node.giveTail())
  57.     PrintF('giveChild() of root = \h\n',root.giveChild())
  58.     PrintF('giveChild() of node = \h\n',node.giveChild())
  59.     PrintF('giveParent() of node = \h\n',node.giveParent())
  60.  
  61.     PrintF('amputation of list from-and-including node \h...\n',intermediate2)
  62.     PrintF('(Notice how the root\as tail etc. are updated)\n')
  63.     intermediate2.free()
  64.  
  65.     PrintF('And showing again: (list is shorter now)\n')
  66.     root.show()
  67.  
  68.     PrintF('Adding three nodes just for fun\n')
  69.     NEW node.make(root)
  70.     NEW node.make(root)
  71.     last := NEW node.make(root)
  72.  
  73.     PrintF('And showing again: (list is longer now)\n')
  74.     root.show()
  75.  
  76.     PrintF('deleting node \h from list...\n',intermediate1)
  77.     intermediate1.delete()
  78.  
  79.     PrintF('And showing again: (list lacks that node now)\n')
  80.     PrintF('(Notice how the parent and child of the nodes around\n the deleted one are updated)\n')
  81.     root.show()
  82.  
  83.     PrintF('deleting last node \h from list...\n',last)
  84.     last.delete()
  85.  
  86.     PrintF('And showing again: (list lacks that node now)\n')
  87.     root.show()
  88.  
  89.     PrintF('\nquitting...\nnow,root = \h\n',root)
  90.      END root                -> frees root and all linked nodes too
  91.     PrintF('root = \h, if it is 0, then root is also freed.\n',root)
  92. ENDPROC
  93.